package cn.xutongxue.book_sales.controller;


import cn.xutongxue.book_sales.base.Result;
import cn.xutongxue.book_sales.entity.Category;
import cn.xutongxue.book_sales.service.CategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author XuTongXue
 * @since 2021-12-02
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/get")
    public Result getAll() {
        List<Category> list = categoryService.list();
        return Result.ok(list);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Category category) {

        if(categoryService.updateById(category)) {
            return Result.ok(null);
        }
        return Result.fail(1401, "修改失败");
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody Category category) {

        if(categoryService.removeById(category.getCategoryId()))
            return  Result.ok(null);
        return Result.fail(1402, "删除失败");
    }

}
